import req from "/@/api/req";
import { ID, PaginationParam, PaginationResult } from "/@/api/models";

export enum Api {
  appUsers = "app-users",
  getPaymentRecords = "payment-records",
  getUsersByIdStr = "app-users/user/{idStr}",
}

export interface AppUserInfo {
  id?: ID;
  status?: number;
  name?: string;
  nickName?: string;
  allowViewingWechat?: number;
  avatar?: string;
  cellphone?: string;
  city?: string;
  companyName?: string;
  demand?: string;
  introduction?: string;
  label?: string;
  personalSignature?: string;
  position?: string;
  receivingAddress?: string;
  shareableResources?: string;
  userType?: string;
  checked?: boolean;
}

export function getPaymentRecords<T = any>(params: PaginationParam<T>) {
  // console.log("getAppUsers", params);
  return req.get<PaginationResult<any>>(
    {
      params,
      url: Api.getPaymentRecords,
    },
    {
      useGlobalLoading: false,
    }
  ) as Promise<PaginationResult<T> | null>;
}

export function getAppUsers<T = any>(params: PaginationParam<T>) {
  // console.log("getAppUsers", params);
  return req.get<PaginationResult<any>>(
    {
      params,
      url: Api.appUsers,
    },
    {
      useGlobalLoading: false,
    }
  ) as Promise<PaginationResult<T> | null>;
}

export function toggleWords(id: ID, status: number) {
  return req.put({
    data: {
      id,
      status,
    },
    url: Api.appUsers,
  });
}

export function getUsersByIdStr(idStr: string) {
  return req.get<AppUserInfo[]>({
    url: Api.getUsersByIdStr.replace("{idStr}", idStr),
  });
}
